package com.xhh.nphm.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xhh.nphm.common.core.domain.entity.Dept;
import com.xhh.nphm.system.domain.MmailGetDealEty;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface MailGetDealMapper extends BaseMapper<MmailGetDealEty> {

    @Select("select pkId,wsCode,fromTopic,fromName,fromTel,dCntAName,convert(varchar(19),YEditTime,20) as yeditTime,ysysDesc,PkId as myOP from mMailGetDeal where StateFlag in (165,166) " +
            "[[and wsCode =#{wsCode}]]" +
            "[[and FromName =#{fromName}]] " +
            "[[and fromTel =#{fromTel}]]" +
            "and IsDel=0  order by PkId desc")
    List<MmailGetDealEty> getMailGetDealList(MmailGetDealEty mmailGetDealEty);
    @Select("select pkId,wsCode,fromTopic,fromName,fromTel,dCntAName,convert(varchar(19),XInputTime,20) as xinputTime,stateDesc,PkId as myOP from mMailGetDeal where IsDel=0" +
            "[[and wsCode =#{wsCode}]]" +
            "[[and FromName =#{fromName}]] " +
            "[[and fromTel =#{fromTel}]]" +
            "order by PkId desc")
    List<MmailGetDealEty> getAcceptanceList(MmailGetDealEty mmailGetDealEty);
@Select("select pkId,wsCode,fromTopic,fromName,fromTel,dCntAName,convert(varchar(19),YEditTime,20) as yeditTime,ysysDesc,PkId as myOP from mMailGetDeal where StateFlag in (161,162)" +
        "[[and wsCode =#{wsCode}]]" +
        "[[and FromName =#{fromName}]] " +
        "[[and fromTel =#{fromTel}]]" +
        " and IsDel=0  order by PkId desc")
    List<MmailGetDealEty> getAbolishList(MmailGetDealEty mmailGetDealEty);
@Select("select pkId,wsCode,fromTopic,fromName,fromTel,dCntAName,convert(varchar(19),YEditTime,20) as yeditTime,wkFmNo,PkId as myOP from mMailGetDeal where StateFlag =155" +
        "[[and wsCode =#{wsCode}]]" +
        "[[and wkFmNo =#{wkFmNo}]]" +
        "[[and FromName =#{fromName}]] " +
        "[[and fromTel =#{fromTel}]]" +
        " and IsDel=0  order by PkId desc")
    List<MmailGetDealEty> getDistributeList(MmailGetDealEty mmailGetDealEty);
    @Select("select pkId,wsCode,spareString,fromTopic,fmAreaName,fromName,fromTel,dfmClaName,dCntAName,convert(varchar(19),FromTime,20) as fromTime,YSpare,PkId as myOP from mMailGetDeal where StateFlag=141" +
            "[[and wsCode =#{wsCode}]]" +
            "[[and FromName =#{fromName}]] " +
            "[[and fromTel =#{fromTel}]]" +
            "[[and dCntAName =#{dCntAName}]] " +
            " and IsDel=0  order by PkId desc")
    List<MmailGetDealEty> getWaitList(MmailGetDealEty mmailGetDealEty);

    @Select("select pkId,wsCode,spareString,fromTopic,fmAreaName,fromName,fromTel,dfmClaName,dCntAName,convert(varchar(19),FromTime,20) as fromTime,yspare,PkId as myOP from mMailGetDeal" +
            " where StateFlag=#{stateFlag}" +
            "[[and wsCode =#{wsCode}]]" +
            "[[and FmCerNO =#{fmCerNo}]]" +
            "[[and FromName =#{fromName}]] " +
            "[[and fromTel =#{fromTel}]]" +
            "[[and dCntAName =#{dCntAName}]] " +
            " and IsDel=0  order by PkId desc")
    List<MmailGetDealEty> mailList(MmailGetDealEty mmailGetDealEty);

    @Select("SELECT COUNT(pkId) FROM mMailGetDeal WHERE YEAR(xinputTime)=#{fpYear} AND MONTH(xinputTime)=#{fpMth} AND DAY(xinputTime)=#{fpDay} AND LEN(wsCode)>0")
    int countSNbyDate(@Param("fpYear") String fpYear, @Param("fpMth") String fpMth, @Param("fpDay") String fpDay);

    /**
     * (网络理政区县)待处理信件M
     *
     * @param params 查询条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WsCode,FromTopic,SpareString,FlagString,FmAreaName,FromName,FromTel,DFmClaName,DCntAName," +
            "convert(varchar(19),FromTime,20) as FromTime from mMailGetDeal " +
            "where StateFlag='1411' and IsDel=0 and FmCerNO=#{deptId} [[and wsCode = #{mail.wsCode}]] [[and FromTel = #{mail.fromTel}]] [[and FromName =#{mail.fromName}]]")
    List<Map<String, Object>> listWaitGetXZJson(HashMap<String,Object> params);

    /**
     * 下级收到来信M
     *
     * @param params 查询条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WsCode,FromTopic,SpareString,FlagString,FmAreaName,FromName,FromTel,DFmClaName,DCntAName,convert(varchar(19),FromTime,20) as FromTime from mMailGetDeal " +
            "where StateFlag='1411' and IsDel=0 and FmCerNo in(select noUnit from bUserDept where areaNo=#{areaNo} and noParent=#{noParent}) " +
            "[[and wsCode = #{mail.wsCode}]] [[and FromTel = #{mail.fromTel}]] [[and FromName =#{mail.fromName}]]")
    List<Map<String, Object>> listThirdMailJson(HashMap<String,Object> params);

    /**
     * （网络理政区县）已处理的信件M
     * @param params  查询条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WsCode,FromTopic,SpareString,FlagString,FromName,FromTel,DCntAName,convert(varchar(19),XInputTime,20) as XInputTime,StateDesc " +
            "from mMailGetDeal where StateFlag in (1611,1621) and FmCerNO=#{deptId} and IsDel=0 and FKInt != 1 " +
            "[[and wsCode = #{mail.wsCode}]] [[and FromTel = #{mail.fromTel}]] [[and FromName =#{mail.fromName}]]")
    List<Map<String, Object>> myGetListXZJson(HashMap<String, Object> params);

    /**
     * 通过信件id查询信件实体
     * @param PkId
     * @return
     */
    @Select("select * from mMailGetDeal where PkId = #{pkId}")
    MmailGetDealEty selectByMailPkId(String pkId);
}
